11 typedef map
<node
, vector
<node
> > graph
;
14 const color WHITE
= 0, GRAY
= 1, BLACK
= 2;
17 map
<node
, color
> colors
;
18 map
<node
, int> d
, low
;
24 void dfs(node v
, bool isRoot
= true){
26 d
[v
] = low
[v
] = ++timeCount
;
27 vector
<node
> neighbors
= g
[v
];
29 for (int i
=0; i
<neighbors
.size(); ++i
){
30 if (colors
[neighbors
[i
]] == WHITE
){ // (v, neighbors[i]) is a tree edge
31 dfs(neighbors
[i
], false);
32 if (!isRoot
&& low
[neighbors
[i
]] >= d
[v
]){
35 low
[v
] = min(low
[v
], low
[neighbors
[i
]]);
37 }else{ // (v, neighbors[i]) is a back edge
38 low
[v
] = min(low
[v
], d
[neighbors
[i
]]);
41 if (isRoot
&& count
> 1){ //Is root and has two neighbors in the DFS-tree
50 while (cin
>> n
&& n
> 0){
51 if (map
> 1) cout
<< endl
;
61 g
[v
] = vector
<node
>();
74 for (graph::iterator i
= g
.begin(); i
!= g
.end(); ++i
){
75 if (colors
[(*i
).first
] == WHITE
){
80 cout
<< "City map #"<<map
<<": " << cameras
.size() << " camera(s) found" << endl
;
81 copy(cameras
.begin(), cameras
.end(), ostream_iterator
<node
>(cout
,"\n"));